import Loadable from 'react-loadable';    // 按需加载依赖包
// 设置按需加载高阶函数
let loadable = (loadercom) => {
    return Loadable({
        loader: loadercom,
        loading: () => {
            return <div>正在加载...</div>
        }
    });
}

// main路由下面的二级路由
const mineRouterTwo = [
    {
        path: "WeChat",
        icon: "#icon-xiaoxi",
        component: loadable(() => import("../pages/main/WeChat")),
        title: "微信"
    },
    {
        path: "addressList",
        icon: "#icon-tongxunlu1",
        component: loadable(() => import("../pages/main/addressList")),
        title: "通讯录"
    },
    {
        path: "discover",
        icon: "#icon-faxian",
        component: loadable(() => import("../pages/main/discover")),
        title: "发现"
    },
    {
        path: "mine",
        icon: "#icon-xiaorentubiao",
        component: loadable(() => import("../pages/main/mine")),
        title: "我的"
    },
    //首页搜索页
    {
        path: "search",
        component: loadable(() => import("../pages/main/WeChat/search")),
    },
    //发起群聊
    {
        path:"initiate",
        component:loadable(() => import("../pages/main/WeChat/InitiateGroupChat/index"))
    },
    //聊天页面
    {
        path:"chatPage",
        component:loadable(() => import("../pages/main/WeChat/ChatPage"))
    },
    //地图
    {
        path:"map",
        component:loadable(() => import("../pages/main/WeChat/ChatPage/Map"))
    },
    //新的朋友
    {
        path:"newFriend",
        component:loadable(() => import ("../pages/main/addressList/newFriend")),
    },
    //仅聊天的朋友
    {
        path:"onlyChatFriend",
        component:loadable(() => import ("../pages/main/addressList/onlyChatFriend")),
    },
    //群聊
    {
        path:"groupChat",
        component:loadable(() => import ("../pages/main/addressList/groupChat")),
    },
    //添加朋友
    {
        path:"addFriend",
        component:loadable(() => import ("../pages/main/addFriend")),
    },
    //朋友详情
    // {
    //     path:"discover",
    //     icon:"#icon-faxian",
    //     component:loadable(() => import ("../pages/main/discover")),
    //     title:"发现",
    //     path:"friendDetail",
    //     component:loadable(() => import ("../pages/main/friendDetail")),
    // },
    //资料设置
    {
        path:"dataDatumSet",
        component:loadable(() => import ("../pages/main/friendDetail/dataDatumSet")),
    },

    {
        path:"circleFriends",
        component:loadable(() => import ("../pages/main/discover/circleFriends .jsx")),
    },
    {
        path:"videoNumber",
        component:loadable(() => import ("../pages/main/discover/videoNumber.jsx")),
    },
    // 设置备注和标签
    {
        path:"setRemark",
        component:loadable(() => import ("../pages/main/friendDetail/setRemark")),
    },
    // 添加好友搜索页
    {
        path:"addFriendSearchPage",
        component:loadable(() => import ("../pages/main/addFriend/addFriendSearchPage")),
    },
    //聊天页面
    {
        path:"chatPage",
        component:loadable(() => import("../pages/main/WeChat/ChatPage"))
    },
    {
        from: "/main",
        to: 'WeChat'
    },
    {
        path: 'personal',
        component: loadable(() => import('../pages/main/mine/personal/personal'))
    },
    {
        path: 'payment',
        component: loadable(() => import('../pages/main/mine/minecomponents/payment/payment'))
    },
    {
        path: 'collect',
        component: loadable(() => import('../pages/main/mine/minecomponents/collect/collect'))
    },
    {
        path: 'set',
        component: loadable(() => import('../pages/main/mine/minecomponents/set/set'))
    }
]

// 路由配置 
const router = [
    {
        path: "/login",
        component: loadable(() => import("../pages/login")),
    },
    {
        path: "/main",
        component: loadable(() => import("../pages/main")),
        children: mineRouterTwo
    },
    {
        path: '/register',
        component: loadable(() => import('../pages/login/register/register'))
    },
    {
        path: '/sigIn',
        component: loadable(() => import('../pages/login/sign/sign'))
    },
    {
        path: "/404",
        component: loadable(() => import("../pages/404"))
    },
    {
        from: "/",
        to: '/main'
    },
    {
        to: '/404'
    },
]

export function mineRouterTwoData() {
    return mineRouterTwo.map(item => {
        if (item.from && item.to) {
            return {
                path: "/main/" + item.path,
                from: item.from,
                to: "/main/" + item.to,
                component: item.component
            }
        } else {
            return {
                path: "/main/" + item.path,
                icon: item.icon,
                title: item.title,
                component: item.component
            }
        }
    })
}

export default router